package nels4561;

import java.util.ArrayList;

/**
 * Represents a single neuron for a NN
 * 
 * @author Michael
 */
public class Neuron {
	
	/**
	 * The output value
	 */
	private double out;
	/**
	 * The sum of the inputs times the weights
	 */
	private double sum;
	/**
	 * The synapses the neuron has inputted into it
	 */
	private ArrayList<Synapse> inSyn;
	
	/**
	 * The default constructor
	 */
	public Neuron()
	{
		inSyn = new ArrayList<Synapse>();;
		out = 0;
	}
	
	/**
	 * A constructor only used for the input nodes
	 * @param out
	 */
	public Neuron(double out)
	{
		this.out = out;
	}
	
	/**
	 * Sums the inputs and multiplies them by the weights
	 * @return the sum
	 */
	public double sumInputs()
	{
		double sum = 0;
		for (int i = 0; i < inSyn.size(); i++)
		{
			double input = inSyn.get(i).getInOutput();
			double w = inSyn.get(i).getWeight();
			
			sum += input*w; 
		}
		this.sum = sum;
		
		return sum;
	}
	
	/**
	 * Was going to use an activation function but
	 * using just th esum worked out fine
	 */
	public void calculateOutput()
	{
		out = sumInputs();
	}
	
	/**
	 * Getter for the output
	 * @return
	 */
	public double getOutput()
	{
		return out;
	}
	
	/**
	 * Setter for the output
	 * @param output
	 */
	public void setOutput(double output)
	{
		out = output;
	}
	
	/**
	 * Adds an input synapse
	 * @param s
	 */
	public void addInputSynapse(Synapse s)
	{
		inSyn.add(s);
	}
	
	/**
	 * Getter for the synapses
	 * @return
	 */
	public ArrayList<Synapse> getSynapses()
	{
		return inSyn;
	}

}
